import {defineStore} from "pinia";
import {ref, computed} from "vue";

// 当第二个参数是函数的时候，那么里面写组合式api
export const useCity = defineStore("city", () => {
  // ref对应的是state
  const cityName = ref<string>("上海");
  const arr = ref<number[]>([1,2,3,4,5, 6]);

  // computed对应的是getters
  const oddArr = computed(() => {
    return arr.value.filter((item) => item  % 2)
  })

  const push = () => {
    setTimeout(() => {
      arr.value.push(7)
    }, 2000)
    
  }

  return {cityName, oddArr, push}
})